package com.xy.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.KafkaListeners;
import org.springframework.messaging.handler.annotation.SendTo;

import java.io.IOException;

@SpringBootApplication
public class KafkaSpringBootApp {
    public static void main(String[] args) throws IOException {
        SpringApplication.run(KafkaSpringBootApp.class, args);
        System.in.read();
    }

    @KafkaListeners(
            value = {
                    @KafkaListener(topics = {"topic01"})
            }
    )
    public void receive(ConsumerRecord<String, String> record) {
        System.out.println("value:" + record.value());
    }

    @KafkaListeners(
            value = {
                    @KafkaListener(topics = {"topic01"})
            }
    )
    @SendTo("topic02")
    public String send(ConsumerRecord<String, String> record) {
        return "from topic01 " + record.value();
    }
}
